package com.wanxi.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.vo.CompanyVO;
import com.wanxi.service.CompanyService;
import com.wanxi.service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/company/add")
public class CompanyAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端的值
        String logo = req.getParameter("logo");
        String phone = req.getParameter("phone");
        String net = req.getParameter("net");
        String email = req.getParameter("email");
        String address = req.getParameter("address");
        String version = req.getParameter("version");
//        3.封装vo
        CompanyVO companyVO=new CompanyVO();
        companyVO.setLogo(logo);
        companyVO.setPhone(phone);
        companyVO.setEmail(email);
        companyVO.setNet(net);
        companyVO.setAddress(address);
        companyVO.setVersion(version);
//       4.调用service
        CompanyService companyService=new CompanyServiceImpl();
//        5.得到返回值
        ResultDTO resultDTO=companyService.add(companyVO);
//        6.响应给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
